﻿using Panuon.WPF.UI;
using Panuon_FileDelete.ViewModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms.VisualStyles;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Panuon_FileDelete.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : WindowX
    {
        public MainViewModel VM { get; set; }
        public MainWindow()
        {
            VM = new MainViewModel();

            InitializeComponent();

            this.DataContext = VM;

            this.Loaded += MainWindow_Loaded;
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                List<string> List_Ex = new List<string>();

                if (ConfigurationManager.AppSettings["FileEx"] != null)
                {
                    List_Ex = ConfigurationManager.AppSettings["FileEx"].ToString().Split(',').ToList();
                }
                else
                {
                    List_Ex = new List<string>() { ".mp4", ".jpg", ".png", ".jpeg", "空文件夹" };
                }
                foreach (string Ex in List_Ex)
                {
                    this.CB_FileEx.Items.Add(new MultiComboBoxItem() { Content = Ex });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("文件类型 初始化异常：" + ex.ToString());
            }
        }

        private void Event_ChooseFilePath(object sender, RoutedEventArgs e)
        {
            using (System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog())
            {
                //调用ShowDialog()方法显示该对话框，该方法的返回值代表用户是否点击了确定按钮
                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
                {
                    VM.FilePath = dialog.SelectedPath.Trim() + @"\";
                }
                else
                {
                    //点击了取消
                    MessageBox.Show("用户取消了选择");
                }
            }
        }

        private void Event_FileTypeChange(object sender, SelectionChangedEventArgs e)
        {
            var aa = (sender as MultiComboBox).SelectedItems;

            List<string> fileTypes = new List<string>();

            foreach (var item in aa)
            {
                fileTypes.Add((item as MultiComboBoxItem).Content.ToString());
            }

            this.VM.FileType = fileTypes;
        }
    }
}
